package com.cqq.print.business.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqq.common.core.bean.PageInfoBean;
import com.cqq.print.business.dao.PAccountDao;
import com.cqq.print.business.dao.PAccountDetailDao;
import com.cqq.print.business.dao.domain.PAccount;
import com.cqq.print.business.dao.domain.PAccountDetail;
import com.cqq.print.business.service.bean.PAccountBean;
import com.cqq.print.business.service.bean.PAccountDetailBean;


/**
 * @author generated
 * @date 2015-07-01
 */


@Service(value="pAccountService")
public class PAccountServiceImpl implements com.cqq.print.business.service.PAccountService{

             @Autowired
             private PAccountDao pAccountDao;
             @Autowired
             private PAccountDetailDao pAccountDetailDao;

			
			public PageInfoBean<PAccountBean> queryPageAccounts(
					Map<String, Object> map) {
				List<PAccountBean> listPABean = null;
				List<PAccount> listPA = pAccountDao.queryAccounts(map);
				int count = pAccountDao.queryAccountsCount(map);
				if(listPA!=null && listPA.size()>0){
					listPABean = new ArrayList<PAccountBean>();
					for (PAccount pa : listPA) {
						PAccountBean paBean = new PAccountBean();
						BeanUtils.copyProperties(pa, paBean);
						listPABean.add(paBean);
					}
				}
				
				return new PageInfoBean<PAccountBean>(listPABean, count);
			}

			
			public void saveAccount(PAccountBean paBean) {
				//审核
				PAccount pa = new PAccount();
				BeanUtils.copyProperties(paBean, pa);
				int paId = pAccountDao.insertSelective(pa);
				
				//审核明细
				for (PAccountDetailBean padBean : paBean.getListPAD()) {
					PAccountDetail pad = new PAccountDetail();
					BeanUtils.copyProperties(padBean, pad);
					pad.setAccountId(paId);
					pAccountDetailDao.insertSelective(pad);
				}
				
			}

			
			public void updateStatus(PAccountBean paBean) {
				PAccount pa = new PAccount();
				BeanUtils.copyProperties(paBean, pa);
				pAccountDao.updateByPrimaryKeySelective(pa);
				
			}

			
			public PAccountBean findById(Integer id) {
				PAccount pa = pAccountDao.selectByPrimaryKey(id);
				PAccountBean paBean = new PAccountBean();
				BeanUtils.copyProperties(pa, paBean);
				return paBean;
			}

}